/*Gyol6cmJgUXqQPmuOmu1BspjC/yBMwyfvgcVqyVkLAyjEGI5bA+5Fd0/+/NRrKxs*/
import {
	allTransferPageCode,
	allTransferHead,
	allTransferBody,
	allTransferSearch,
	proTransferPageCode,
	proTransferHead,
	proTransferBody,
	purTransferPageCode,
	purTransferHead,
	purTransferBody,
	equipTransferPageCode,
	equipTransferHead,
	equipTransferBody,
	assetTransferPageCode,
	assetTransferHead,
	assetTransferBody,
	profitTransferPageCode,
	profitTransferHead,
	profitTransferBody,
	KeyMap,
	contractTransferPageCode,
	contractTransferHead,
	contractTransferBody,
	contractTransferSearch,
	contractAppcode
} from '../constants';
import translateData from '../utils/translateData';
import { ajax, toast } from 'nc-lightapp-front';

import ampub from 'ampub';
const { utils: { multiLangUtils: { getMultiLangByID }, msgUtils: { showMessage, MsgConst, showConfirm } } } = ampub;

export default function clickSerachBtn(isRefAddLine, billvo) {
	let searchVal = this.props.search.getAllSearchData(allTransferSearch);
	if (searchVal) {
		let querydata = this.props.search.getQueryInfo('all_search', true);
		if (querydata) {
			querydata.pagecode = 'all_transfer';
			//userdefObj合同用
			querydata.userdefObj = {
				busiTypes: 'ISNOTBUSITYPE',
				headCode: 'head',
				bodyCode: 'bodyvos'
			};
		}
		ajax({
			url: '/nccloud/fa/assettransfer/searchall.do',
			data: querydata,
			success: (res) => {
				searchAllCallback.call(this, res);
			}
		});
	}
}

export function messageTriggerSearchCallback(res) {
	const { props: { transferTable } } = this;
	let { success, data } = res;
	if (success) {
		let allData = [];
		if (data) {
			let keys = Object.keys(data);
			if (keys && keys.length) {
				let vos = data[keys[0]];
				let userjson = JSON.parse(vos[0].userjson);
				userjson.sumCount = parseInt(userjson.sumCount);
				userjson.currentCount = parseInt(userjson.currentCount);
				if (userjson.sumCount > userjson.currentCount) {
					// 本次查询出待生的固定资产卡片有 {sumCount }条，数据过大，请先批量处理完成 {currentCount } 张固定资产卡片，然后再继续处理。
					toast({
						content: getMultiLangByID('201201512A-000054', {
							sumCount: userjson.sumCount,
							currentCount: userjson.currentCount
						}),
						color: 'success'
					});
				}
			}

			//采购转固单
			if (data[purTransferPageCode]) {
				this.clickTab('3', () => {
					this.updateDataFn = () => {
						transferTable.setTransferTableValue(
							purTransferHead,
							purTransferBody,
							data[purTransferPageCode],
							'pk_transasset',
							'pk_transasset_b'
						);
						let pks = [];
						data[purTransferPageCode].map((item) => {
							item.body[purTransferBody].rows.map((bodyvo) => {
								pks.push(bodyvo.values.pk_transasset_b.value);
							});
						});
						transferTable.setTheCheckRows(purTransferHead, pks);
					};
				});
				return;
			}
			//工程转固单
			if (data[proTransferPageCode]) {
				this.clickTab('4', () => {
					this.updateDataFn = () => {
						transferTable.setTransferTableValue(
							proTransferHead,
							proTransferBody,
							data[proTransferPageCode],
							'pk_transasset',
							'pk_transasset_b'
						);
						let pks = [];
						data[proTransferPageCode].map((item) => {
							item.body[proTransferBody].rows.map((bodyvo) => {
								pks.push(bodyvo.values.pk_transasset_b.value);
							});
						});
						transferTable.setTheCheckRows(proTransferHead, pks);
					};
				});
				return;
			}
			//资产租入
			if (data[contractTransferPageCode]) {
				this.clickTab('6', () => {
					this.updateDataFn = () => {
						transferTable.setTransferTableValue(
							contractTransferHead,
							contractTransferBody,
							data[contractTransferPageCode],
							'pk_contract',
							'pk_contract_eq'
						);
						let pks = [];
						data[contractTransferPageCode].map((item) => {
							item.body[contractTransferBody].rows.map((bodyvo) => {
								pks.push(bodyvo.values.pk_contract_eq.value);
							});
						});
						transferTable.setTheCheckRows(contractTransferHead, pks);
					};
				});
				return;
			}

			showMessage(this.props, {
				color: 'warning',
				content: getMultiLangByID('201201512A-000037')
			});
		} else {
			transferTable.setTransferTableValue(allTransferHead, allTransferBody, [], 'pk', 'pk_b');
			showMessage(this.props, { color: 'warning', content: getMultiLangByID('201201512A-000037') });
		}
	}
}
export function searchAllCallback(res) {
	let { success, data } = res;
	if (success) {
		let allData = [];
		if (data) {
			let keys = Object.keys(data);
			if (keys && keys.length) {
				let vos = data[keys[0]];
				let userjson = JSON.parse(vos[0].userjson);
				userjson.sumCount = parseInt(userjson.sumCount);
				userjson.currentCount = parseInt(userjson.currentCount);
				if (userjson.sumCount > userjson.currentCount) {
					// 本次查询出待生的固定资产卡片有 {sumCount }条，数据过大，请先批量处理完成 {currentCount } 张固定资产卡片，然后再继续处理。
					toast({
						content: getMultiLangByID('201201512A-000054', {
							sumCount: userjson.sumCount,
							currentCount: userjson.currentCount
						}),
						color: 'success'
					});
				}
			}

			//新增资产审批单
			if (data[assetTransferPageCode]) {
				let newAsset_billtype = {
					bill_type: { value: 'HN', display: getMultiLangByID('201201512A-000033') }
				};
				let destNewAssetDatas = translateData(
					data[assetTransferPageCode],
					assetTransferHead,
					assetTransferBody,
					allTransferHead,
					allTransferBody,
					KeyMap.KeyMapNewToAll,
					newAsset_billtype
				);
				allData.push(...destNewAssetDatas);
			}

			//设备卡片
			if (data[equipTransferPageCode]) {
				let equip_billtype = {
					bill_type: { value: '4A00', display: getMultiLangByID('201201512A-000032') }
				};
				let destEquipDatas = translateData(
					data[equipTransferPageCode],
					equipTransferHead,
					null,
					allTransferHead,
					allTransferBody,
					KeyMap.KeyMapEquipToAll,
					equip_billtype
				);
				allData.push(...destEquipDatas);
			}

			//采购转固单
			if (data[purTransferPageCode]) {
				let pur_billtype = {
					bill_type: { value: 'HJ-02', display: getMultiLangByID('201201512A-000034') }
				};
				let destPurDatas = translateData(
					data[purTransferPageCode],
					purTransferHead,
					purTransferBody,
					allTransferHead,
					allTransferBody,
					KeyMap.KeyMapPurToAll,
					pur_billtype
				);
				allData.push(...destPurDatas);
			}
			//工程转固单
			if (data[proTransferPageCode]) {
				let project_billtype = {
					bill_type: { value: 'HJ-01', display: getMultiLangByID('201201512A-000035') }
				};
				let destProjectDatas = translateData(
					data[proTransferPageCode],
					proTransferHead,
					proTransferBody,
					allTransferHead,
					allTransferBody,
					KeyMap.KeyMapProToAll,
					project_billtype
				);
				allData.push(...destProjectDatas);
			}
			//盘盈单
			if (data[profitTransferPageCode]) {
				let profit_billtype = {
					bill_type: { value: 'HS', display: getMultiLangByID('201201512A-000036') }
				};
				let destProfitDatas = translateData(
					data[profitTransferPageCode],
					profitTransferHead,
					profitTransferBody,
					allTransferHead,
					allTransferBody,
					KeyMap.KeyMapProfitToAll,
					profit_billtype
				);
				allData.push(...destProfitDatas);
			}
			//资产租入
			if (data[contractTransferPageCode]) {
				let contract_billtype = {
					bill_type: { value: '4A3A', display: getMultiLangByID('201201512A-000055') }
				};
				let destContractDatas = translateData(
					data[contractTransferPageCode],
					contractTransferHead,
					contractTransferBody,
					allTransferHead,
					allTransferBody,
					KeyMap.KeyMapContractToAll,
					contract_billtype
				);
				allData.push(...destContractDatas);
			}
			this.props.transferTable.setTransferTableValue(allTransferHead, allTransferBody, allData, 'pk', 'pk_b');
			if (allData.length == 0) {
				showMessage(this.props, {
					color: 'warning',
					content: getMultiLangByID('201201512A-000037')
				});
			}
		} else {
			this.props.transferTable.setTransferTableValue(allTransferHead, allTransferBody, null, 'pk', 'pk_b');
			showMessage(this.props, { color: 'warning', content: getMultiLangByID('201201512A-000037') });
		}
	}
}

/*Gyol6cmJgUXqQPmuOmu1BspjC/yBMwyfvgcVqyVkLAyjEGI5bA+5Fd0/+/NRrKxs*/